package com.witsight.platform.model;

import java.io.Serializable;

import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.annotation.Transient;
import org.springframework.data.domain.Persistable;


/**   
 * 说明：基本的实体类
 * @Title: BaseEntity.java 
 * @Package com.witsight.platform.model 
 * @See: {@link Persistable}
 *       {@link IBaseObject}
 * Copyright: Copyright (c) 2017
 * Company:sany huax witsight team by product
 * @author: penght  
 * @date: 2017年9月11日 下午5:44:15 
 * @version: V1.0
 *
 */
public abstract class BaseObject<ID extends Serializable> implements IBaseObject, Persistable<ID> {
	private static final long serialVersionUID = 6795465982293989656L;
	
	/**
	 * Log variable for all child classes. Uses LoggerFactory.getLog(getClass()) from Commons Logging
	 */
	@Transient
	protected final Logger log = LoggerFactory.getLogger(getClass());
	/**
	 * 
	 * 说明：构建Json的String对象
	 * @Title: toStringBuilder
	 * @See: {@link ToStringBuilder}
	 * @author penght
	 * @return ToStringBuilder
	 * @date: 2017年10月16日 上午8:49:01
	 */
	protected ToStringBuilder toStringBuilder() {
		return new ToStringBuilder(this, ToStringStyle.JSON_STYLE)
			.append("id",this.getId());
	}
	/**
	 * Returns a multi-line String with key=value pairs.
	 * 
	 * @return a String representation of this class.
	 */
	public String toString() {
		return toStringBuilder().build();
	}
	/**
	 * Compares object equality. When using Hibernate, the primary key should not be a part of this
	 * comparison.
	 * 
	 * @param o
	 *            object to compare to
	 * @return true/false based on equality tests
	 */
	public abstract boolean equals(Object o);

	/**
	 * When you override equals, you should override hashCode. See "Why are equals() and hashCode()
	 * importation" for more information: http://www.hibernate.org/109.html
	 * 
	 * @return hashCode
	 */
	public int hashCode() {
		return new HashCodeBuilder().append(getId()).toHashCode();
	}	
}
